<div class="jxksgsmb" >
    <div class="jxksgsmb-left">
        <div class="jxksgsmb-left-title">绩效科室列表</div>
        <div class="jxksgsmb-left-content">
            <ul id="tt"></ul>
        </div>
    </div>
    <div class="jxksgsmb-right">
        <div class="jxksgsmb-right-top">
            <div class="jxksgsmb-right-top-title">
                公式设置
                <span class="hrp-btn hrp-btn-delete"  style="float:right;margin-top: 3px;"><i class="fa fa-close" style="padding-right: 4px;"></i>删除</span>
                <span class="hrp-btn hrp-btn-add" style="float:right;margin-top: 3px;"><i class="fa fa-plus" style="padding-right: 4px;"></i>保存公式</span>
            </div>
            <div class="jxksgsmb-right-top-bottom">

            </div>
        </div>
        <div class="jxksgsmb-right-bottom">
            <div class="jxksgsmb-right-bottom-left">
                <ul id="clzb"></ul>
            </div>
            <div class="jxksgsmb-right-bottom-center">
                <ul id="mathtick"></ul>
            </div>
            <!--<div class="jxksgsmb-right-bottom-right">-->
                <!--<ul id="blzb"></ul>-->
            <!--</div>-->
        </div>
    </div>

</div>

<script type="text/javascript">

    var jxksgsmb={
        init:function () {
            this.initEvents();
            this.initJxksTree();
            this.initblzb();
            this.initclzb();
            this.initMathFlag();

        },
        initEvents:function () {

            var that = this;

            $(".jxksgsmb-right-top-bottom").on("click",".jxksgsmb-gs-item",function () {
                $(this).addClass("active").siblings().removeClass("active")
            })
            
            $(".hrp-btn-delete").click(function () {
                if( $(".jxksgsmb-right-top-bottom").children(".active").length){
                    $(".jxksgsmb-right-top-bottom").children(".active").remove();
                }else{
                    $.messager.show({
                        title:'消息提醒',
                        msg:'请选择要删除的项目',
                        timeout:1000,
                        showType:'slide'
                    });
                }
            })

            $(".hrp-btn-add").on("click",function () {
                that.updateGs();
            })
            
        },
        initJxksTree:function () {

            var that = this;

            $('#tt').tree({
                url:"/common/getJxksTree",
                onClick:function (node) {
                    $.post("/jxksgsmb/getJxksgsmb",{"jxksdm":node.id},function (result) {
                        $(".jxksgsmb-right-top-bottom").html(result.data);
                    })
                },
                animate:true
            });

            return that;
        },
        initclzb:function () {

            var that = this;

            $('#clzb').tree({
                url:"/jjfact/getJjfactTree",
                queryParams:{
                    "zblb":2
                },
                onClick:function (node) {
                    that.nodeClick(node);
                },
                animate:true
            });

            return that;
        },
        initblzb:function () {
            var that = this;

            $('#blzb').tree({
                url:"/jxkhzb/getKhzbTreeListByZblb",
                queryParams:{
                    "zblb":1
                },
                onClick:function (node) {
                    that.nodeClick(node);
                },
                animate:true
            });
            return that;
        },
        initMathFlag:function () {

            var that = this;


            $.post("/common/getDicList",{"id":-1,"lbdm":4},function (result) {
                var data = [{"id":"-1","parentId":null,"text":"算数符号","iconCls":null,"state":null,"menuUrl":null,"sortId":null,"children":[]}];
                var ss = data[0].children=result;

                $('#mathtick').tree({
                    data:data,
                    onClick:function (node) {
                        that.nodeClick(node);
                    },
                    animate:true
                });
            })


            return that;
        },
        nodeClick:function (node) {
            var html = '<span class="jxksgsmb-gs-item">'+node.text+'</span>';
            $(".jxksgsmb-right-top-bottom").append(html);
        },
        updateGs:function () {

            var node = $('#tt').tree("getSelected")
            if(!node){
                $.messager.show({
                    title:'提示',
                    msg:'请选择绩效科室',
                    timeout:1000,
                    showType:'slide'
                });
            }
            var jxksdm = node.id;
            var jxksmc = node.text;

            var nodeGs = $(".jxksgsmb-gs-item");
            var gsArr=[];
            var gsparams = '';
            var gsmcHtml = '';
            if(nodeGs.length){
                for(var i=0;i<nodeGs.length;i++){
                    gsArr.push(nodeGs.eq(i).text());
                    gsmcHtml +='<span class="jxksgsmb-gs-item">'+nodeGs.eq(i).text()+'</span>';
                }
                $.post("jxksgsmb/updateGsmb",{"gsmb":gsArr.join(","),"jxksdm":jxksdm,"jxksmc":jxksmc,"gsmcHtml":gsmcHtml},function () {

                })
            }else{
                $.messager.show({
                    title:'消息提醒',
                    msg:'请设置公式',
                    timeout:1000,
                    showType:'slide'
                });
            }
        }
    }

    $(function () {
        jxksgsmb.init();
    })
    
</script>